//
//  CustomTabBarController.m
//  ProjectA
//
//  Created by lanouhn on 15/5/22.
//  Copyright (c) 2015年 lanouhn. All rights reserved.
//

#import "CustomTabBarController.h"

@interface CustomTabBarController ()


- (void)_setup;//设置tabBarController
- (UINavigationController *)_navigationControllerWithClass:(Class)class;//根据指定的视图控制器类型创建对象以及导航控制器

@end

@implementation CustomTabBarController
#pragma __private method__
- (UINavigationController *)_navigationControllerWithClass:(Class)class {
    UIViewController *aVC = [[class alloc]init];
    UINavigationController *naviVC = [[UINavigationController alloc]initWithRootViewController:aVC];

    [aVC release];
    return [naviVC autorelease];
}
//造tabBar
- (void)_setup {
    //tabBar的image
    NSArray *imageName = @[@"tab_latest" , @"tab_hero" ,@"jieshuo"];
    //tabBar的文字
    NSArray *titles = @[@"焦点视频" ,@"英雄" ,@"解说"];
    NSArray *className = @[@"VideoController" , @"HeroController" , @"CommentController"];
    NSMutableArray *viewControllers = [NSMutableArray array];
    //造三个navigationController
    for (int i = 0; i < className.count; i ++) {
        //创建试图控制器
        UINavigationController *aNavi = [self _navigationControllerWithClass:NSClassFromString(className[i])];
        
        //设置tabBar的Items
        aNavi.tabBarItem = [[[UITabBarItem alloc]initWithTitle:titles[i] image:[[UIImage imageNamed:imageName[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]selectedImage:[[UIImage imageNamed:[imageName[i] stringByAppendingString:@"_selected"]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]]autorelease];
            [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:188.0 / 255 green:28.0 / 255 blue:38.0 / 255 alpha:1]];
        [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
               //把导航栏加入到数组中
        [viewControllers addObject:aNavi];
    }
    self.viewControllers = viewControllers;
}
#pragma __lazyloading
#pragma __buttonAction__
- (void)handleDelect:(UIBarButtonItem *)sender{}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self _setup];
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
